/*
 * igo: com.cctv.igo.admin.scheduler.dto.TaskTypeDefinition.java Create On 2011-5-3 下午08:01:49 By Q-Wang
 * $Revision: 1.2 $
 */
package com.ctvit.scheduler.dto;

import java.io.Serializable;
import java.util.Map;

import com.ctvit.scheduler.parser.TaskParser;
import com.ctvit.scheduler.service.ScheduleService;
import com.ctvit.framework.web.context.ContextHolder;

/**
 * @author <a href="mailto:apeidou@gmail.com">Q-Wang</a>
 *
 */
public class TaskTypeDefinition implements Serializable {

	private static Map<String,TaskTypeDefinition> taskTypes;

	/**
	 * @return the taskTypes
	 */
	public static Map<String, TaskTypeDefinition> getTaskTypes() {
		if (taskTypes==null) {
			taskTypes = ContextHolder.getBean(ScheduleService.class).getTaskTypeDefinition();
		}
		return taskTypes;
	}

	/**
	 * @param taskTypes the taskTypes to set
	 */
	public static void setTaskTypes(Map<String, TaskTypeDefinition> taskTypes) {
		if (TaskTypeDefinition.taskTypes!=null) {
			throw new IllegalStateException("Scheduler Task Types Already resolved.");
		}
		TaskTypeDefinition.taskTypes = taskTypes;
	}

	public static TaskParser getTaskParser(String type) {
		TaskTypeDefinition typeDefinition = getTaskTypes().get(type);
		if (typeDefinition==null) {
			throw new IllegalStateException("");
		}
		return typeDefinition.getParserInstance();
	}

	private TaskParser parserInstance;

	/**
	 * @return the parserInstance
	 */
	public TaskParser getParserInstance() {
		return parserInstance;
	}

	/**
	 * @param parserInstance the parserInstance to set
	 */
	public void setParserInstance(TaskParser parserInstance) {
		this.parserInstance = parserInstance;
	}

	private String type;

	private String parser;

	private String description;

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the parser
	 */
	public String getParser() {
		return parser;
	}

	/**
	 * @param parser the parser to set
	 */
	public void setParser(String parser) {
		this.parser = parser;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
}
